<template>
	<view class="refund">	
		<view class="top">
			<image :src="data.productPic" mode="scaleToFill"></image>
			<view class="rightBox">
				<view class="title">
					{{data.productName}}
				</view>
				<view class="desction">
					{{data.productAttr}}
				</view>
			</view>
		</view>
		<view class="box">
			<view class="reason" v-if="type == 1">
				<text>货物状态</text>
				<view class="select" @tap="getStatus">
					{{status?status:'请选择'}}<image src="../../static/images/more_icon.png" mode="scaleToFill"></image>
				</view>
			</view>
			<view class="reason">
				<text>退款原因</text>
				<view class="select" @tap="getReason">
					{{reason?reason:'请选择'}}<image src="../../static/images/more_icon.png" mode="scaleToFill"></image>
				</view>
			</view>
			<view>
				<text>退款金额</text>
				<view class="priceBox">
					￥<text class="price">{{data.payAmount}}</text>
				</view>
			</view>
			<view>
				<text>退款说明</text>
				<input type="text" v-model="value" placeholder="选填" />
			</view>
		</view>
		
		<view class="submitBtn" @tap="submit">
			提交
		</view>
	<cancel-order v-if="isShowBottom" @closeBottom = "closeSheet"></cancel-order>
	<select-type v-if="isShowBottom2" @closeBottom = "closeSheet2"></select-type>
	</view>
</template>
<script>
	import cancelOrder from '../../components/bbh-sheet/cancelOrder.vue'
	import selectType from '../../components/bbh-sheet/selectType.vue'
	export default{
		components:{
			cancelOrder,
			selectType
		},
		data() {
			return {
				data:{},
				reasonList:[],
				isShowBottom:false,
				isShowBottom2:false,
				reason:"",
				reasonID:"",
				value:"",
				status:"",
				type:"",
				receivedStatus:0 //收到货1 未收到0
			}
		},
		onLoad(e) {
			this.data = JSON.parse(decodeURIComponent(e.data));
			this.type = e.type;
		},
		methods:{
			getReason(){
				let data = {}
				this.$http.post('/api/v1.0/order/drawbackReason',data,res=>{
					this.reasonList = res.data.data;
					this.isShowBottom = true;
				})
			},
			getStatus(){
				let data = {}
				this.$http.post('/api/v1.0/order/drawbackReason',data,res=>{
					this.isShowBottom2 = true;
				})
			},
			submit(){
				//申请售后仅退款
				if(this.type == 1){
					if(this.status == ""){
						uni.showToast({
							title:"请选择货物状态",
							icon:"none"
						})
						return false;
					}
				}
				
				//未确认收货退款  申请售后退货退款
				if(this.reason == ""){
					uni.showToast({
						title:"请选择退款原因",
						icon:"none"
					})
					return false;
				}
				
				
				let data = {
					  "amount": this.data.payAmount,
					  "currencyType": "RMB",
					  "orderId": this.data.orderId,
					  "orderItemId": this.data.id,
					  "productId": this.data.productId,
					  "receivedStatus": this.receivedStatus,
					  "ref3thId": this.data.ref3thId,
					  "refundReason": this.reason,
					  "refundReasonId": this.reasonID,
					  "refundType": 101,//101仅退款  107退货退款
					  "skuId": this.data.productSkuId,
					  ext:this.value
				}
				//当用户选择退货退款
				if(this.type == 2){
					data.refundType = 107
				}
				
				this.$http.post('/api/v1.0/order/refund/apply',data,res=>{
					if(res.data.status == '000000'){
						uni.redirectTo({
							url:'revocation?data=' + encodeURIComponent(JSON.stringify(this.data))
						})
					}
				})
			},
			//退款原因
			closeSheet(e){
				if(e){
					this.reasonID = e;
					for (let i = 0; i < this.reasonList.length; i++) {
						if(this.reasonList[i].drawbackReasonId == e){
							this.reason = this.reasonList[i].drawbackReason;
							this.isShowBottom = false;
							return;
						}
					}	
				}else{
					this.isShowBottom = false;
				}
				
			},
			//货物状态
			closeSheet2(e){
				this.receivedStatus = e;
				if(e == 0){
					this.status = '未收到货'
				}
				if(e == 1){
					this.status = '已收到货'
				}
				this.isShowBottom2 = false;
				
			},
			
		}
	}
</script>

<style lang="scss">
	.refund{
		min-height: 100vh;
		background-color: #f2f2f2;
		padding: 40upx 0;
		.top{
			background-color: #fff;
			border-radius: 20upx;
			padding: 20upx;
			box-sizing: border-box;
			display: flex;
			justify-content: flex-start;
			align-items: center;
			image{
				width: 140upx;
				height: 140upx;
				margin-right: 20upx;
			}
			.rightBox{
				width: 530upx;
				.title{
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					color: #333;
					font-size: 28upx;
				}
				.desction{
					color: #808080;
					font-size: 22upx;
					display: -webkit-box;
					overflow: hidden; 
					white-space: normal!important;
					text-overflow: ellipsis;
					word-wrap: break-word; 
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
				}
			}
			
		}
		.box{
			margin-top: 20upx;
			background-color: #fff;
			&>view{
				display: flex;
				align-items: center;
				height: 80upx;
				border-bottom: 1upx solid #F2F2F2;
				padding: 0 30upx;
				box-sizing: border-box;
				&>text{
					color: #333;
					font-size: 28upx;
					margin-right: 50upx;
				}
				.priceBox{
					color: #F63810;
					font-size: 24upx;
					.price{
						font-size: 30upx;
					}
				}
				input{
					width: 450upx;
					height: 40upx;
					font-size: 24upx;
					position: relative;
					z-index: 10;
					
				}
			}
			.reason{
				justify-content: space-between;
				.select{
					font-size: 24upx;
					color: #999999;
					image{
						width: 22upx;
						height: 22upx;
						margin-left: 10upx;
					}
				}
			}
		}
		.submitBtn{
			background:linear-gradient(0deg,rgba(232,39,27,1),rgba(250,94,52,1));
			border-radius: 44upx;
			width: 670upx;
			margin: 0 auto;
			height: 88upx;
			line-height: 80upx;
			font-size: 32upx;
			color: #fff;
			font-weight: bold;
			text-align: center;
			margin-top: 60upx;
		}
		
		
	}
</style>
